/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JInfoGiocatore.java
 *
 * Created on 5-feb-2009, 9.46.14
 */

package monopoli.gui;

import javax.swing.JFrame;
import monopoli.*;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.ImageIcon;
import org.jdesktop.application.Action;

/**
 *
 * @author Claudio
 */
public class JInfoGiocatore extends javax.swing.JDialog {

    private String giocatore = null;
    private int money = 0;
    private ArrayList<String> possedimenti = null;
    private String pedina = null;
    private MonopoliView mv;

    public JInfoGiocatore(JFrame parent, boolean modal, MonopoliView aThis) {
        super(parent, modal);
        mv=aThis;
        initComponents();
    }

    /*public JInfoGiocatore(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();

    }*/

    public String getGiocatore() {
        return giocatore;
    }

    public void setGiocatore(String giocatore) {
        this.giocatore = giocatore;
        //ricavo altre info
        int idGiocatore = Monopoli.getMonopoliPartita().ricavaIdGiocatore(giocatore);
        money = Monopoli.getMonopoliPartita().getSoldiGiocatore(idGiocatore);
        possedimenti = Monopoli.getMonopoliPartita().getPossedimenti(idGiocatore);
        pedina= Monopoli.getMonopoliPartita().getPedinaGiocatore(idGiocatore);

        //mostro
        jName.setText(giocatore);
        jSoldi.setText(Integer.toString(money)  + " €");
      

        String[] data = new String[possedimenti.size()];
        int nn = 0;
        Iterator it = possedimenti.iterator();
        while (it.hasNext()) {
            String p = (String) it.next();
            data[nn] = p;
            nn++;
        }
        JlstPossedimenti.setListData(data);

        String path = "../resources/" + pedina + ".png";
        java.net.URL imgURL = getClass().getResource(path);
        if (imgURL == null) {
                System.out.println("PATH IMMAGINE NON TROVATO!");
        } else {
                //System.out.println(path);
                lblPedina.setIcon(new ImageIcon(imgURL));
        }



}



    
    /** Creates new form JInfoGiocatore */
    public JInfoGiocatore(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        lblPedina = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        JlstPossedimenti = new javax.swing.JList();
        jName = new javax.swing.JLabel();
        jSoldi = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N
        setResizable(false);

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(monopoli.MonopoliApp.class).getContext().getResourceMap(JInfoGiocatore.class);
        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        lblPedina.setText(resourceMap.getString("lblPedina.text")); // NOI18N
        lblPedina.setName("lblPedina"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jScrollPane6.setName("jScrollPane6"); // NOI18N

        JlstPossedimenti.setName("JlstPossedimenti"); // NOI18N
        JlstPossedimenti.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                JlstPossedimentiMouseClicked(evt);
            }
        });
        jScrollPane6.setViewportView(JlstPossedimenti);

        jName.setFont(resourceMap.getFont("jName.font")); // NOI18N
        jName.setText(resourceMap.getString("jName.text")); // NOI18N
        jName.setName("jName"); // NOI18N

        jSoldi.setText(resourceMap.getString("jSoldi.text")); // NOI18N
        jSoldi.setName("jSoldi"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(monopoli.MonopoliApp.class).getContext().getActionMap(JInfoGiocatore.class, this);
        jButton1.setAction(actionMap.get("chiudi")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(58, 58, 58)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(29, 29, 29))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblPedina, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4))
                                .addGap(44, 44, 44)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jName, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
                                    .addComponent(jSoldi, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
                                    .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))))
                .addGap(74, 74, 74))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jName, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jSoldi, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(lblPedina, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(25, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void JlstPossedimentiMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_JlstPossedimentiMouseClicked
        // TODO add your handling code here:
        // TODO add your handling code here:
        String s = new String();
        s = (String)JlstPossedimenti.getSelectedValue();
        mv.showInfoProp(s);
       
}//GEN-LAST:event_JlstPossedimentiMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                JInfoGiocatore dialog = new JInfoGiocatore(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    @Action
    public void chiudi() {
        this.dispose();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList JlstPossedimenti;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jName;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JLabel jSoldi;
    private javax.swing.JLabel lblPedina;
    // End of variables declaration//GEN-END:variables

}
